<?php
namespace app\index\model;

use think\Db;
use app\common\model\ToolModel;

class EditorModel
{
    /**
     * 获取编辑审核详细信息
     * @author LSH
     * @return array
     */
    public static function dbGetEditorList($param)
    {
        $where = [];
        !empty($param['skus'])&&$where['sku'] = ['IN',explodeStr($param['skus'])];
        !empty($param['spus'])&&$where['spu'] = ['IN',explodeStr($param['spus'])];
        $db = Db::table('setting_editor')->where($where)->order('id','desc');
        return \app\common\service\ToolService::downOrReturn($db, $param);
    }

    /**
     * 获取编辑审核详细信息
     * @author LSH
     * @return array
     */
    public static function dbUpdateOperatorInfo($param)
    {
        Db::startTrans();
        try{
            $data = [];
            $data['sku']=$param['sku'];
            $data['operator']=UID;
            $data['update_time']=date('Y-m-d H:i:s',time());
            !empty($param['spu'])&&$data['spu']=$param['spu'];
            !empty($param['img'])&&$data['img_operator']=$param['img'];
            !empty($param['edit'])&&$data['edit_operator']=$param['edit'];
            ToolModel::dbInsertOrUpdate('setting_editor', [$data]);

            $assign = [];
            $where = ['sku'=>$param['sku'],'manufacture_status'=>['<=',2]];
            if(isset($param['img']) && $param['img']) {
                $assign['img_operator'] = $param['img'];
                Db::table('manage_img_audit')->where($where)->update(['operator'=>$param['img']]);
            }
            
            if(isset($param['edit']) && $param['edit']){
                $assign['edit_operator'] = $param['edit'];
                Db::table('manage_edit_audit')->where($where)->update(['operator'=>$param['edit']]);   
            }
            
            if(!empty($assign)) Db::table('manage_assign')->where(['sku'=>$param['sku']])->update($assign);

            Db::commit();
            return 1;
        } catch (\Exception $e) {
            Db::rollback();
            return 0;
        }
    }
}
